package com.hwl.eduservice.controller.admin;


import com.hwl.commonutils.result.RespBean;
import com.hwl.eduservice.pojo.Video;
import com.hwl.eduservice.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author long
 * @since 2021-09-21
 */
@Api(tags = "课时管理")
@RestController
@RequestMapping("/admin/eduVideo")
public class VideoController {

    @Resource
    private VideoService videoService;

    @ApiOperation("新增课时")
    @PostMapping("save")
    public RespBean save(@RequestBody Video video) {
        if (videoService.save(video)) {
            return RespBean.ok().message("添加课时成功！");
        }
        return RespBean.error().message("添加课时失败！");
    }

    @ApiOperation("根据id查询课时")
    @GetMapping("get/{id}")
    public RespBean getById(@PathVariable String id) {
        return RespBean.ok().data(videoService.getById(id));
    }


    @ApiOperation("修改课时")
    @PutMapping("update")
    public RespBean update(@RequestBody Video video) {
        if (videoService.updateById(video)) {
            return RespBean.ok().message("修改课时成功！");
        }
        return RespBean.error().message("修改课时失败！");
    }

    @ApiOperation("删除课时")
    @DeleteMapping("remove/{id}")
    public RespBean removeById(@PathVariable String id) {
        //删除课时时删除视频
        videoService.removeVideoById(id);

        if (videoService.removeById(id)) {
            return RespBean.ok().message("删除课时成功！");
        }
        return RespBean.error().message("删除课时失败！");
    }
}

